﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SWEN3Application.Classes;
using System.Drawing.Printing;

namespace SWEN3Application
{
    public partial class DetailsForm : Form
    {
        PrintDocument PrintDoc = new PrintDocument();
        PrintPreviewDialog PreviewDialog = new PrintPreviewDialog();

        public DetailsForm(BookingList b, Rooms r, Invoice i)
        {
            InitializeComponent();
            setResultView(b, r, i);
            PreviewDialog.Document = PrintDoc;
            PrintDoc.OriginAtMargins = true;
            PrintDoc.PrintPage += PDoc_PrintPage;
        }

        public void setResultView(BookingList b, Rooms r, Invoice i)
        {
            BookingNo.Text = b.BookingNo.ToString();
            LastName.Text = b.LastName;
            FirstName.Text = b.FirstName;
            AdultsNo.Text = b.AdultsNo.ToString();
            ChildsNo.Text = b.ChildsNo.ToString();
            PhoneNo.Text = b.PhoneNo;
            EmailAddress.Text = b.EmailAddress;
            Address.Text = b.Address;
            Remarks.Text = b.Remarks;
            Country.Text = b.Country;

            RoomNo.Text = r.RoomNo.ToString();
            RoomType.Text = r.RoomType;
            RoomRates.Text = "$ " + r.RoomRates;
            CheckIn.Text = r.CheckIn.ToString();

            if (i != null)
            {
                DetailsGroupBox.Text = "Check Out Details";

                label20.Visible = true;
                InvoiceNo.Text = i.InvoiceId.ToString();

                label9.Visible = true;
                CheckOut.Text = r.CheckOut.ToString();

                Title.Text = "Invoice";
                PayableAmt.Text = i.calculateTotalToCurrency().ToString();
            }
            else
            {
                DetailsGroupBox.Text = "Check In Details";

                label20.Visible = false;
                InvoiceNo.Text = "";

                label9.Visible = false;
                CheckOut.Text = "";

                Title.Text = "Booking";
            }
        }

        private void Print_Click(object sender, EventArgs e)
        {
            PreviewDialog.ShowDialog();
        }

        private void PDoc_PrintPage(object sender, PrintPageEventArgs e)
        {
            this.FormBorderStyle = FormBorderStyle.None;
            int temptHeight = this.Height;
            this.Height = 800;
            Bitmap bmp = new Bitmap(this.Width - 20, this.Height - 100);
            this.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height)); //Takes the Snap of the Exact WindowForm size as Bitmap image
            e.Graphics.DrawImage(bmp, 0, 0);
            this.Height = temptHeight;
            this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
        }

        private void Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
